<%@ Page language="c#" Codebehind="Upload.aspx.cs" AutoEventWireup="True" Inherits="CrossFactory.SiteNote.XmlEditor.Upload" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>
			<%= pageResourceManager.GetString("pagetitle")%>
		</title>
		<script src="../JScript/jquery-1.4.2.min.js" type="text/javascript"></script>
    <link href="StyleSheets/XmlEditor.css" type="text/css" rel="stylesheet" />
    <script language="javascript" type="text/javascript">

        function onChange(element) {
        <% if(HttpContext.Current.Request.QueryString["mode"] == "gallery")
        { %>
            if(element.value != "")
                $(element).parent().parent().clone().insertBefore("#trUploadS");
            else {
                if ($(":file").length > 1) {
                    $(element).parent().parent().remove();
                }
            }
            <%} %>
        }
        
        var bMustClose = true;
        var uploadBtnId = null;
        var fileUploadId = null;
        var newUri = null;
        var zipUri = null;
			
			function UnLoading()
			{
				if (bMustClose)
				{
					Close();
				}
			}

			function ShowPreview()
			{
				var fileUp;
				var filePath;
				var pos;
				var ext;
				
				if (fileUploadId != null)
				{
					fileUp = document.all[fileUploadId];
					
					if (fileUp != null)
					{
						filePath = fileUp.value;
						
						if (filePath == "")
						{
							alert('<%= pageResourceManager.GetString("chooseimagefirst")%>');
						}
						else
						{
							pos = filePath.lastIndexOf(".");
							
							if (pos != -1)
							{
								ext = filePath.substr(pos + 1).toLowerCase()
								
								if (ext == "jpg" || ext == "jpeg" || ext == "bmp" || ext == "gif" || ext == "png")
								{
									window.opener.showModalDialog(window.xmlEditor.xmlEditorPath + 'UploadPreview.aspx', filePath, "dialogHeight:450px; dialogWidth:400px; edge: Raised; center: Yes; help: No; scroll:no; resizable: No; status: No;");
								}
								else
								{
									alert('<%= pageResourceManager.GetString("wrongformat")%>');
								}
							}
							else
							{
								alert('<%= pageResourceManager.GetString("wrongformat")%>');
							}
						}
					}
				}
			}
			
			function Loaded()
			{
				if (document.all["ChkResize"] != null)
				{
					document.all['ChkResize'].checked = false;
				}
				document.all["uri"].value = window.opener.currentFileUri;
				if (window.opener.currentFileWidth != null && document.all["TxtWidth"] != null)
				{
					document.all["TxtWidth"].value = window.opener.currentFileWidth;
				}
				if (window.opener.currentFileHeight != null && document.all["TxtHeight"] != null)
				{
					document.all["TxtHeight"].value = window.opener.currentFileHeight;
				}
			}

			function Submitting()
			{
				bMustClose = false;
				
				if (uploadBtnId != null)
				{
					window.setTimeout("DisableButton()", 150);
				}

				window.document.body.style.cursor = "wait";
				
				return true;
			}

			function DisableButton()
			{
				document.all[uploadBtnId].disabled = true;
			}

			function Close()
			{
				bMustClose = false;
				
				if (document.all["status"].value == "saved")
				{
                window.opener.FileUploaded(newUri, zipUri);
				}
				else
				{
					window.opener.UploadCanceled();
				}

				window.close();
			}
			
			function Resize_OnClick()
			{
				var cssLabelName;
				
				if(document.all['ChkResize'].checked)
				{
					cssLabelName = "label";
					bgColorBorder = "#444444";
				}
				else
				{
					cssLabelName = "labelDisable";
					bgColorBorder = "#808080";
				}
					
				
				document.all['td_autoimagesize'].className = cssLabelName;
				document.all['td_widthimagesize'].className = cssLabelName;
				document.all['td_heightimagesize'].className = cssLabelName;
				
				document.all['TxtHeight'].disabled = !document.all['ChkResize'].checked; 
				document.all['TxtWidth'].disabled = !document.all['ChkResize'].checked; 
				
				document.all['td_border1'].bgColor = bgColorBorder;
				document.all['td_border2'].bgColor = bgColorBorder;
				document.all['td_border3'].bgColor = bgColorBorder;
				document.all['td_border4'].bgColor = bgColorBorder;
				document.all['td_border5'].bgColor = bgColorBorder;
				document.all['td_border6'].bgColor = bgColorBorder;

			
			
			
			}

			</script>
	</HEAD>
	<body MS_POSITIONING="FlowLayout" bottommargin="0" leftmargin="0" rightmargin="0" topmargin="0" onload="Loaded()" onunload="UnLoading()">
		<form id="Upload" method="post" runat="server" onsubmit="return Submitting();" encType="multipart/form-data">
			<table id="Main" cellSpacing="0" cellPadding="0" border="0" style="WIDTH:100%;HEIGHT:100%">
				<tr height="31">
					<td colspan="5">
						<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
							<tr>
								<td width="100%">
									<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
										<tr>
											<td width="100%" background="Images/HeaderLeft.gif"><img src="Images/Transp.gif" height="1" width="100%"></td>
											<td align="right"><img src="Images/HeaderRight.gif"></td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td width="7" background="Images/BackgroundLeft.gif"><img src="Images/Transp.gif" width="7"></td>
					<td width="7"><img src="Images/Transp.gif" width="7"></td>
					<td id="content" width="100%" height="100%" class="label" valign="center" align="middle">
						<input id="status" runat="server" type="hidden" NAME="status"><input id="uri" name="uri" runat="server" type="hidden">
						<table id="UploadTable" runat="server" border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
							<tr>
								<td class="label"><nobr><%= pageResourceManager.GetString("choosefile")%></nobr></td>
								<td class="label">&nbsp;:&nbsp;</td>
								<td class="value" width="100%"><input id="file" name="file" type="file" class="value" onchange="onChange(this);" style="WIDTH:100%"></td>
							</tr>
							<tr id="trUploadS">
								<td colspan="3">
									<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
										<tr>
											<td width="21" height="21"><asp:CheckBox id="ChkResize" runat="server" onclick="Resize_OnClick();"></asp:CheckBox></td>
											<td class="labelDisable" id="td_autoimagesize"><nobr><%= pageResourceManager.GetString("autoimagesize")%></nobr><img src="Images/Transp.gif" width="10"></td>
											<td width="100%">
												<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
													<tr>
														<td height="10"><img src="Images/Transp.gif" width="1"></td>
													</tr>
													<tr>
														<td height="1" bgcolor="#444444" id="td_border1"><img src="Images/Transp.gif" width="1"></td>
													</tr>
													<tr>
														<td height="10"><img src="Images/Transp.gif" width="1"></td>
													</tr>
												</table>
											</td>
											<td width="1">
												<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
													<tr>
														<td height="10"><img src="Images/Transp.gif" width="1"></td>
													</tr>
													<tr>
														<td height="11" bgcolor="#444444" id="td_border2"><img src="Images/Transp.gif" width="1" height="11"></td>
													</tr>
												</table>
											</td>
										</tr>
										<tr>
											<td width="21">
												<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
													<tr>
														<td width="10"><img src="Images/Transp.gif" width="10"></td>
														<td width="1" bgcolor="#444444" id="td_border3"><img src="Images/Transp.gif" width="1"></td>
														<td width="10"><img src="Images/Transp.gif" width="10"></td>
													</tr>
												</table>
											</td>
											<td colspan="2">
												<table border="0" cellpadding="0" cellspacing="0">
													<tr>
														<td class="labelDisable" id="td_widthimagesize"><nobr><%= pageResourceManager.GetString("imagewidth")%></nobr></td>
														<td class="label">&nbsp;:&nbsp;</td>
														<td class="value">
															<asp:TextBox id="TxtWidth" runat="server" CssClass="value" Width="150" Enabled="False">100</asp:TextBox>
															<asp:RegularExpressionValidator id="imageWidthValidator" runat="server" ControlToValidate="TxtWidth" ValidationExpression="\d{0,3}" ErrorMessage="* max. value 999"></asp:RegularExpressionValidator>
														</td>
													</tr>
													<tr>
														<td class="labelDisable" id="td_heightimagesize"><nobr><%= pageResourceManager.GetString("imageheight")%></nobr></td>
														<td class="label">&nbsp;:&nbsp;</td>
														<td class="value">
															<asp:TextBox id="TxtHeight" runat="server" CssClass="value" Width="150" Enabled="False"></asp:TextBox>
															<asp:RegularExpressionValidator id="imageHeightValidator" runat="server" ControlToValidate="TxtHeight" ValidationExpression="\d{0,3}" ErrorMessage="* max. value 999"></asp:RegularExpressionValidator>
														</td>
													</tr>
												</table>
											</td>
											<td width="1">
												<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
													<tr>
														<td bgcolor="#444444" id="td_border4"><img src="Images/Transp.gif" width="1" height="1"></td>
													</tr>
												</table>
											</td>
										</tr>
										<tr>
											<td>
												<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
													<tr>
														<td width="10"><img src="Images/Transp.gif" width="10" height="1"></td>
														<td width="11" bgcolor="#444444" id="td_border5"><img src="Images/Transp.gif" width="11" height="1"></td>
													</tr>
												</table>
											</td>
											<td width="100%" bgcolor="#444444" colspan="3" id="td_border6"><img src="Images/Transp.gif" width="11" height="1"></td>
										</tr>
									</table>
								</td>
							</tr>
							<tr>
								<td colspan="3"><img src="Images/Transp.gif" width="1" height="11"></td>
							</tr>
						</table>
						<asp:Label ID="Message" Runat="server"></asp:Label>
					</td>
					<td width="7"><img src="Images/Transp.gif" width="7"></td>
					<td width="9" height="100%">
						<table border="0" cellpadding="0" cellspacing="0" width="9" height="100%">
							<tr height="32">
								<td width="9"><img src="Images/BackgroundTopRight.gif"></td>
							</tr>
							<tr height="100%">
								<td width="9" background="Images/BackgroundRight.gif"></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr height="40">
					<td colspan="5">
						<table border="0" cellpadding="0" cellspacing="0" height="100%">
							<tr>
								<td height="8"><img src="Images/FooterLeft.gif"></td>
								<td width="100%">
									<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
										<tr>
											<td width="100%" background="Images/FooterCenter.gif" height="8"></td>
											<td height="8"><img src="Images/FooterRight.gif" width="255" height="8"></td>
										</tr>
									</table>
								</td>
							</tr>
							<tr>
								<td align="right" width="100%" colSpan="3">
									<table id="Table5" width="100%" height="100%" border="0" style="BACKGROUND :url(Images/Footer.gif) no-repeat right 50%">
										<tr>
											<td width="100%"></td>
											<td><input id="Preview" type="button" runat="server" name="Preview" onclick="ShowPreview();"></td>
											<td><asp:Button id="UploadButton" runat="server" Text="Update" onclick="UploadButton_Click" /></td>
											<td><input id="Cancel" type="button" name="Close" value='<%= pageResourceManager.GetString("cancelButton")%>' onclick="window.Close();"></td>
											<td width="1"></td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</form>
	</body>
</HTML>
